package com.qcit.older.usercenter.common

import android.annotation.SuppressLint
import android.util.Log
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Action
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers

@SuppressLint("CheckResult")
fun <T> Observable<T>.sub(onNext: Consumer<T>, onError: Consumer<Throwable>, onComplete: Action) {
    this.subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            onNext.accept(it)
        }, {
            it.message?.let { it1 -> Log.e("lib093", it1) }
            onError.accept(it)
            onComplete.run()
        }, {
            onComplete.run()
        })
}

@SuppressLint("CheckResult")
fun <T> Observable<T>.sub(onNext: Consumer<T>, onError: Consumer<Throwable>) {
    this.subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            onNext.accept(it)
        }, {
            onError.accept(it)
        })
}